import { View } from "../../../mvc/core/View";
import { IClean } from "../../../../com/gengine/core/IClean";
import { LayerManager } from "../../manager/LayerManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { Global } from "../../../../com/gengine/global/Global";
import { GImageBitmap } from "../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../resource/ImagesConst";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { ObjCreate } from "../common/ObjCreate";
import { Language } from "../../../../extend/language/Language";
import { MoneyItem } from "../common/item/MoneyItem";
import { EPrictUnit } from "../../../../Message/Public/EPrictUnit";
import { Cache } from "../../cache/Cache";
import { BossFieldCliffordCell } from "./cell/BossFieldCliffordCell";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { TodayNotTipUtil } from "../../../common/TodayNotTipUtil";
import { TodayNoTipsConst } from "../../../component/gconst/TodayNoTipsConst";
import { Alert } from "../../../../com/mui/controls/Alert";
import { SNewBattleFieldInspireInfo } from "../../../../Message/Public/SNewBattleFieldInspireInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { GButton } from "../../../../com/mui/controls/GButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
type int = number;
//class BossFieldCliffordView
    
    export  class BossFieldCliffordView extends View implements IClean
    {
        constructor()
        {
            super();
            this._cliffordArray = [];
            this.layer = LayerManager.uiLayer;
            this.addEventListener(flash.events.Event.ADDED_TO_STAGE, this.onAddToStage);
            this.addEventListener(flash.events.Event.REMOVED_FROM_STAGE, this.onRemoveFromStage);
            this.init();
            return;
        }

        /* internal  */onAddToStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.addEventListener(EventName.StageResize, this.onStageResize);
            this.resetPos();
            return;
        }

        /* internal  */onRemoveFromStage(arg1: Object /* flash.events.Event */): void
        {
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        /* internal  */onStageResize(arg1: DataEvent): void
        {
            this.resetPos();
            return;
        }

        /* internal  */resetPos(): void
        {
            this.x = (Global.stage.stageWidth - 460) / 2;
            this.y = (Global.stage.stageHeight - 400) / 2;
            return;
        }

        /* internal  */init(): void
        {
            this._bg = new GImageBitmap(ImagesConst.BossFieldBg, 0, 0);
            this.addChild(this._bg);
            var loc1=GlobalStyle.textFormat1;
            loc1.size = 13;
            this._tfCurrent = ObjCreate.createTextField("", 53, 81, 500, 20, this, loc1, true);
            this._tfNext = ObjCreate.createTextField("", 53, 109, 500, 20, this, loc1, true);
            ObjCreate.createBg(10, 132, 430, 1, this, ImagesConst.SeptalLine);
            this._closeBtn = ObjCreate.createGButton("", 365, 45, 19, 19, this, "CloseButton");
            this._cliffordCell1 = this.createCliffordCell(1);
            this._cliffordCell2 = this.createCliffordCell(2);
            this._cliffordCell3 = this.createCliffordCell(3);
            this._cliffordCell4 = this.createCliffordCell(4);
            this._cliffordCell5 = this.createCliffordCell(5);
            ObjCreate.createTextField(Language.getString(44702), 40, 250, 220, 20, this, GlobalStyle.textFormatGreen);
            this._tfClifford = ObjCreate.createGTextField(Language.getString(44703), 250, 250, 65, 20, this);
            this._moneyItem = new MoneyItem();
            this._moneyItem.unit = EPrictUnit._EPriceUnitGold;
            ObjCreate.setObjAttri(this._moneyItem, 260, 250, -1, -1, this);
            this._tfNoClifford = ObjCreate.createGTextField(Language.getString(44704), 250, 250, 120, 20, this);
            this._tfNoClifford.visible = false;
            this._btnClifford = ObjCreate.createGButton(Language.getString(44705), 368, 247, 50, 22, this, "ButtonRedMini");
            this._btnClifford.addEventListener(flash.events.MouseEvent.CLICK, this.onClickClifford);
            this._closeBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onClickClose);
            if (Cache.instance.bossField.inspireInfo) 
            {
                this.updateInspire(Cache.instance.bossField.inspireInfo);
            }
            return;
        }

        /* internal  */createCliffordCell(arg1: int): BossFieldCliffordCell
        {
            var loc1=new BossFieldCliffordCell();
            loc1.update(GameDefConfig.instance.getBossfieldClifford(arg1));
            ObjCreate.setObjAttri(loc1, 47 + (arg1 - 1) * 80, 140, -1, -1, this);
            this._cliffordArray.push(loc1);
            return loc1;
        }

        /* internal  */onClickClose(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            return;
        }

        /* internal  */onClickClifford(arg1: Object /* flash.events.MouseEvent */): void
        {
            TodayNotTipUtil.toDayNotTip(TodayNoTipsConst.BossFieldCliffordNotTip, this.confirmClifford, Language.getStringByParam(44706, this._nextCliffordPrice), null, Alert.OK | Alert.CANCEL);
            return;
        }

        /* internal  */confirmClifford(): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.BossFieldClifford));
            return;
        }

        public updateInspire(arg1: SNewBattleFieldInspireInfo): void
        {
            var loc1=arg1.attackLevel;
            this._btnClifford.enabled = loc1 < 5;
            var loc2=GameDefConfig.instance.getBossfieldClifford(loc1);
            var loc3=GameDefConfig.instance.getBossfieldClifford(loc1 + 1);
            this._tfCurrent.visible = !(loc2 == null);
            this._tfNext.visible = !(loc3 == null);
            if (loc2) 
            {
                this._tfCurrent.htmlText = Language.getStringByParam(44707, HTMLUtil.getHtmlByComp(loc2.name), HTMLUtil.getHtmlByComp(loc2.text2));
                if (this._currentCell) 
                {
                    this._currentCell.selected = false;
                }
                this._currentCell = this._cliffordArray[(loc1 - 1)];
                if (this._currentCell) 
                {
                    this._currentCell.selected = true;
                }
            }
            if (loc3) 
            {
                this._tfNext.htmlText = Language.getStringByParam(44708, HTMLUtil.getHtmlByComp(loc3.name), HTMLUtil.getHtmlByComp(loc3.text2));
                this._moneyItem.update(int(loc3.text3), EPrictUnit._EPriceUnitGold);
                this._nextCliffordPrice = int(loc3.text3);
                this._tfClifford.visible = true;
                this._moneyItem.visible = true;
                this._tfNoClifford.visible = false;
            }
            else 
            {
                this._tfClifford.visible = false;
                this._moneyItem.visible = false;
                this._tfNoClifford.visible = true;
            }
            if (loc2 && loc3) 
            {
                this._tfCurrent.y = 81;
                this._tfNext.y = 109;
            }
            else if (loc2) 
            {
                this._tfCurrent.y = 95;
            }
            else 
            {
                this._tfNext.y = 95;
            }
            return;
        }

        public clean(): void
        {
            Dispatcher.removeEventListener(EventName.StageResize, this.onStageResize);
            return;
        }

        public static get instance(): BossFieldCliffordView
        {
            if (!BossFieldCliffordView._instance) 
            {
                BossFieldCliffordView._instance = new BossFieldCliffordView();
            }
            return BossFieldCliffordView._instance;
        }

        public static hasInstance(): Boolean
        {
            return !(BossFieldCliffordView._instance == null);
        }

        /* internal */ /* var */_bg: GImageBitmap;

        /* internal */ /* var */_tfCurrent: Object /* flash.text.TextField */;

        /* internal */ /* var */_tfNext: Object /* flash.text.TextField */;

        /* internal */ /* var */_closeBtn: GButton;

        /* internal */ /* var */_cliffordArray: Array<any>;

        /* internal */ /* var */_cliffordCell1: BossFieldCliffordCell;

        /* internal */ /* var */_cliffordCell2: BossFieldCliffordCell;

        /* internal */ /* var */_cliffordCell3: BossFieldCliffordCell;

        /* internal */ /* var */_cliffordCell4: BossFieldCliffordCell;

        /* internal */ /* var */_cliffordCell5: BossFieldCliffordCell;

        /* internal */ /* var */_currentCell: BossFieldCliffordCell;

        /* internal */ /* var */_nextCliffordPrice: int=2;

        /* internal */ /* var */_tfClifford: GTextFiled;

        /* internal */ /* var */_moneyItem: MoneyItem;

        /* internal */ /* var */_tfNoClifford: GTextFiled;

        /* internal */ /* var */_btnClifford: GButton;

        /* internal */ static /* var */_instance: BossFieldCliffordView;
    }
